package visualizacao;

import java.awt.Color;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.JSeparator;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;
import java.awt.event.InputMethodEvent;
import java.awt.event.InputMethodListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyVetoException;
import java.beans.VetoableChangeListener;

import javax.swing.JTextField;
import javax.swing.JScrollPane;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;

import org.jdesktop.swingx.JXDatePicker;

@SuppressWarnings("serial")
public class VTelaCadastroAtor extends JFrame {

	static public JFrame janela;
	public JPanel painel = new JPanel();
	public JTable tbAtores;
	public JTextField tfNome;
	
	public JXDatePicker jxDtNascimento;
	
	public JLabel lbNome,lbDtNascimento;
	public JButton btGravar,btNovo,btEditar,btExcluir;
	public JSeparator separator;
	public JScrollPane scrollPane;
	public DefaultTableModel model;

	/**
	 * Create the frame.
	 */
	public VTelaCadastroAtor() {
		
		janela = new JFrame("Cadastro de Atores");
		janela.setSize(450, 300);
		janela.setLocationRelativeTo(null);        
		janela.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		janela.setResizable(false);
		painel.setBackground(Color.WHITE);
		painel.setLayout(null);
		
		
		lbNome = new JLabel("Nome:");
		lbNome.setBounds(23, 212, 57, 14);
		painel.add(lbNome);
		
		lbDtNascimento = new JLabel("Data de Nascimento:");
		lbDtNascimento.setBounds(23, 237, 131, 14);
		painel.add(lbDtNascimento);
		
		tbAtores = new JTable();
		tbAtores.setBackground(Color.LIGHT_GRAY);
		tbAtores.setBounds(23, 11, 387, 128);
		
		model = new DefaultTableModel();
		String[] colunas = new String[]{"ID","Matricula", "Nome", "Sobrenome"};
		model.setColumnIdentifiers(colunas);
		tbAtores.setModel(model);
		tbAtores.getColumnModel().getColumn(0).setPreferredWidth(0);
		tbAtores.getColumnModel().getColumn(0).setResizable(false);
		
		
		
		scrollPane = new JScrollPane();
		scrollPane.setBounds(23, 11, 387, 128);
		scrollPane.setViewportView(tbAtores);
		painel.add(scrollPane);
		
		separator = new JSeparator();
		separator.setBounds(10, 181, 414, 14);
		painel.add(separator);
		
		btNovo = new JButton("Novo");
		btNovo.setBounds(23, 147, 89, 23);
		//btNovo.setEnabled(false);
		painel.add(btNovo);
		
		btEditar = new JButton("Editar");
		btEditar.setBounds(174, 147, 89, 23);
		btEditar.setEnabled(false);
		painel.add(btEditar);
		
		btExcluir = new JButton("Excluir");
		btExcluir.setBounds(321, 147, 89, 23);
		btExcluir.setEnabled(false);
		painel.add(btExcluir);
		
		tfNome = new JTextField();
		tfNome.setBounds(94, 209, 195, 20);
		painel.add(tfNome);
		
		jxDtNascimento = new JXDatePicker();
		jxDtNascimento.setBounds(151, 234, 138, 20);
		jxDtNascimento.setFormats(new String [] { "dd/MM/yyyy" });  
		painel.add(jxDtNascimento);
		
		btGravar = new JButton("Gravar");
		btGravar.setBounds(332, 212, 89, 43);
		btGravar.setEnabled(false);
		painel.add(btGravar);
		
		
		janela.getContentPane().add(painel);
	}
	
	public void adicionarEventos(ActionListener acao) {
		btGravar.addActionListener(acao);
		btEditar.addActionListener(acao);
		btNovo.addActionListener(acao);
		btExcluir.addActionListener(acao);
	}
	
	public void exibir() {
		janela.setVisible(true);
	}
	
	public void fechar() {
		janela.dispose();
	}
	
	public void atualizarTabela() {
		this.tbAtores.setModel(this.model);
	}
}
